   /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * main.cc
 * Copyright (C) blankito 2007 <jamateos@gmail.com>
 * 
 * main.cc is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * main.cc is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <libglademm/xml.h>
#include <gtkmm.h>
#include <iostream>


#ifdef ENABLE_NLS
#  include <libintl.h>
#endif

using namespace std;

/* For testing propose use the local (not installed) glade file */
/* #define GLADE_FILE PACKAGE_DATA_DIR"/yafrid-ng/glade/yafrid-ng.glade" */
#define GLADE_FILE "yafridng.glade"

Glib::RefPtr<Gnome::Glade::Xml> refXml;

void launchButton_clicked_cb()
{
	Gtk::FileChooserButton* fc = 0;
	refXml->get_widget("filePath", fc);

	if(fc){
		string file = fc ->get_filename();
		if(file == ""){
			Gtk::MessageDialog advice("You should choose a file\n for rendering");
			advice.set_title("Error Message");
			advice.run();
		}
	}
}

int initializeInterface()
{
	//Load the Glade file and instiate its widgets:
	try
		{
			refXml = Gnome::Glade::Xml::create(GLADE_FILE);
		}
	catch(const Gnome::Glade::XmlError& ex)
		{
			std::cerr << ex.what() << std::endl;
			return 1;
		}

	Gtk::Window* main_win = 0;
	refXml->get_widget("YafridNG", main_win);
	
	main_win->set_title("YafridNG");
	Gtk::Button* launchButton = 0;
	refXml->get_widget("launchButton", launchButton);
	
	if(launchButton)
		{
			launchButton->signal_clicked().connect(sigc::ptr_fun(launchButton_clicked_cb));
		}
	
	return 0;
}

int
main (int argc, char *argv[])
{
	Gtk::Main kit(argc, argv);
	
	//	launchButton->signal_clicked().connect(sigc::mem_fun(NULL, &launchButton_clicked_cb));
	
	initializeInterface();

	Gtk::Window* main_win = 0;
	refXml->get_widget("YafridNG", main_win);
	if (main_win)
	{
		kit.run(*main_win);
	}
	return 0;
}
